home *** CD-ROM | disk | FTP | other *** search
- /*
- *--- main.cpp ----------------------------------------------------------
- * Copyright (c) 1992-96 Adobe Systems, Inc. All rights reserved.
- *
- * PageMaker plug-in.
- *-----------------------------------------------------------------------
- */
-
- /* ---------------- PageMaker SDK include files ---------------- */
- #include "PMPlugin.h"
- #include "CIObjectAccess.h"
-
- /* ---------------- Plug-in include files ---------------- */
- #include "ExportF.h"
- #include "Convert.h"
-
- #ifdef MACINTOSH
- #include "WinTypes.h"
- #endif //MACINTOSH
-
- /* ---------------- Cross-platform include files ---------------- */
- #include <string.h>
- #include <stdio.h>
-
- /* ---------------- Platform specific include files ---------------- */
- #ifdef MACINTOSH
- #include <types.h>
- #ifndef powerc
- #include <A4Stuff.h>
- #include <SetUpA4.h>
- #endif
- #else
- #include <windows.h>
- #endif
-
- /* ---------------- Type definitions ---------------- */
-
- /* ---------------- Definitions ---------------- */
- #define SUCCESS 1
- #define FAILURE 0
- #define STAYINMEMORY -1
-
- /* ---------------- PageMaker (New)SDK include files ---------------- */
- #include "CIInterfaceManager.h"
- #include "PMEvent.h"
- #include "CIBasic.h"
- #include "PMInterfaceIDs.h"
- #include "CICommandsAndQueries.h"
-
- /* ---------------- Function declarations ---------------- */
- PMXErr DoInvoke( PMMessage *pMsg );
- PMXErr DoLoad(PMMessage* pMsg);
- PMXErr DoRegister(PMMessage* pMsg);
- PMXErr DoInvoke(PMMessage* pMsg);
- PMXErr DoEvent(PMMessage* pMsg);
- PMXErr DoSysEvent(PMMessage* pMsg);
- PMXErr DoAcquireInterface(PMMessage* pMsg);
- PMXErr DoReleaseInterface( PMMessage *pMsg );
- PMXErr DoUnload(PMMessage* pMsg);
- PMXErr DoShutdown(PMMessage* pMsg);
- PMXErr DoCleanup(PMMessage* pMsg);
-
- #ifdef MACINTOSH
- #ifdef powerc
- #pragma export on
- #endif
- PMXErr main(PMMessage *pMsg);
- #ifdef powerc
- #pragma export off
- #endif
- #else
- BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID pReserved);
- #endif
-
- #ifdef powerc
- #pragma export on
- #endif
- PMXErr ConvertMeas(kUnits srcType, float srcSize, kUnits destType, char *destStr,
- float *destSize, size_t *destStrLen, PMBool localise);
- #ifdef powerc
- #pragma export off
- #endif
-
- /* ---------------- Globals ---------------- */
- sPMParamBlockPtr thePB = NULL;
- CICommandQuery *pCmdQry = (CICommandQuery *)NULL;
- CIInterfaceManager *gpIntfMgr;
- extern kUnits gSrcType, gDestType;
- extern PMBool gLocalise;
-
- #ifdef WINDOWS
- HINSTANCE ghDLL;
-
- BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID pReserved)
- {
- ghDLL = hDLL;
-
- return TRUE;
- }
- #endif
-
- /*
- *--- main --------------------------------------------------------------------
- * Entry point for plug-in control tasks.
- *-----------------------------------------------------------------------------
- */
- PMXErr main(PMMessage *pMsg)
- {
- PMXErr result;
- #if __MWERKS__ && __MC68K__
- long oldA4 = SetCurrentA4();
- RememberA4();
- #endif
-
- gpIntfMgr = pMsg->pInterfaceMgr;
-
- switch ( pMsg->opCode ) {
- case kPMLoad:
- result = DoLoad(pMsg);
- break;
-
- case kPMRegister:
- result = DoRegister(pMsg);
- break;
-
- case kPMInvoke:
- result = DoInvoke(pMsg);
- break;
-
- case kPMEvent:
- result = DoEvent(pMsg);
- break;
-
- case kPMSysEvent:
- result = DoSysEvent(pMsg);
- break;
-
- case kPMAcquireInterface:
- result = DoAcquireInterface(pMsg);
- break;
-
- case kPMReleaseInterface:
- result = DoReleaseInterface(pMsg);
- break;
-
- case kPMUnload:
- result = DoUnload(pMsg);
- break;
-
- case kPMShutdown:
- result = DoShutdown(pMsg);
- break;
-
- case kPMCleanup:
- result = DoCleanup(pMsg);
- break;
-
- default:
- result = 0;
- }
-
- #if __MWERKS__ && __MC68K__
- SetA4(oldA4);
- #endif
-
- return result;
- }
-
- /*
- *--- DoRegister --------------------------------------------------------------
- * Called if Plug-in registers for Events or adds new interfaces to PM.
- *-----------------------------------------------------------------------------
- */
- PMXErr DoRegister( PMMessage *pMsg )
- {
- PMXErr result = SUCCESS;
- gpIntfMgr = pMsg->pInterfaceMgr;
-
- gpIntfMgr->AddPMInterface(PIConvertName);
-
- /*
- {
- LPVOID theInterface;
- gpIntfMgr->AcquirePMInterface(PIConvertName, &theInterface);
- gpIntfMgr->ReleasePMInterface(PIConvertName, &theInterface);
- }
- */
- return result;
- }
-
- /*
- *--- DoAcquireInterface ------------------------------------------------------
- * Called when other plug-ins acquire the exported interface.
- *-----------------------------------------------------------------------------
- */
- PMXErr DoAcquireInterface( PMMessage *pMsg )
- {
- PMXErr result = SUCCESS;
-
- PMInterface *pPMInterface = (PMInterface*)pMsg->pPMData;
-
- if (strcmp(pPMInterface->pInterfaceName, PIConvertName) == 0)
- pPMInterface->pInterface = (LPVOID *)ConvertMeas;
- else
- return FAILURE;
-
-
- return result;
- }
-
- /*
- *--- DoReleaseInterface ------------------------------------------------------
- * Called when other plug-ins release the acquired interface.
- *-----------------------------------------------------------------------------
- */
- PMXErr DoReleaseInterface( PMMessage *pMsg )
- {
- PMXErr result = SUCCESS;
-
- return result;
- }
-
- /*
- *--- DoInvoke ----------------------------------------------------------------
- *
- *-----------------------------------------------------------------------------
- */
- PMXErr DoInvoke( PMMessage *pMsg )
- {
- PMXErr result;
-
- return SUCCESS;
- }
-
- /*
- *--- DoLoad ------------------------------------------------------------------
- *
- *-----------------------------------------------------------------------------
- */
- PMXErr DoLoad(PMMessage* pMsg)
- {
- #pragma unused (pMsg)
- return CQ_SUCCESS;
-
- }
-
- /*
- *--- DoEvent -----------------------------------------------------------------
- *
- *-----------------------------------------------------------------------------
- */
- PMXErr DoEvent(PMMessage* pMsg)
- {
- #pragma unused (pMsg)
- return CQ_SUCCESS;
- }
-
- /*
- *--- DoSysEvent --------------------------------------------------------------
- *
- *-----------------------------------------------------------------------------
- */
- PMXErr DoSysEvent(PMMessage* pMsg)
- {
- #pragma unused (pMsg)
- return CQ_SUCCESS;
- }
-
- /*
- *--- DoUnload ----------------------------------------------------------------
- *
- *-----------------------------------------------------------------------------
- */
- PMXErr DoUnload(PMMessage* pMsg)
- {
- #pragma unused (pMsg)
- return STAYINMEMORY; //we want to stay in memory
- }
-
- /*
- *--- DoShutdown --------------------------------------------------------------
- *
- *-----------------------------------------------------------------------------
- */
- PMXErr DoShutdown(PMMessage* pMsg)
- {
- #pragma unused (pMsg)
- return CQ_SUCCESS;
- }
-
- /*
- *--- DoCleanup ---------------------------------------------------------------
- *
- *-----------------------------------------------------------------------------
- */
- PMXErr DoCleanup(PMMessage* pMsg)
- {
- #pragma unused (pMsg)
- return CQ_SUCCESS;
- }
-
- /*
- *--- ConvertMeas -------------------------------------------------------------
- * Actual Interface exported by this plug-in.
- *
- * In:
- * Source Unit Type
- * Source Value
- * Destination Unit Type
- * Boolean -- Localise the string? Comma instead of point for decimal sep.
- *
- * Out:
- * Converted value as a string with unit type
- * Converted value as number
- * String lenght
- *-----------------------------------------------------------------------------
- */
- PMXErr ConvertMeas(kUnits srcType, float srcSize, kUnits destType, char *destStr,
- float *destSize, size_t *destStrLen, PMBool localise)
- {
- PMXErr result = SUCCESS;
-
- if (!gpIntfMgr->AcquirePMInterface((unsigned long)PMIID_CMDQRY, (LPVOID *)&pCmdQry))
- pCmdQry->Retrieve (&thePB);
- else
- return CQ_FAILURE;
-
- result = Convert(srcType, srcSize, destType, destStr, destSize, destStrLen, localise);
-
- gpIntfMgr->ReleasePMInterface((LPVOID *)pCmdQry);
-
- return result;
- }
-